//
//  ForgetPwdToModife.m
//  HB
//
//  Created by 陶秋安 on 16/3/7.
//  Copyright © 2016年 孙智慧. All rights reserved.
//

#import "ForgetPwdToModife.h"
#import "ForgetPwdOperation.h"
#import "LoginAction.h"

@implementation ForgetPwdToModife

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.lblUserName.text= self .userName;
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //显示导航栏
    [super.navigationController setNavigationBarHidden:NO animated:TRUE];
    
}

- (IBAction)btnFinish:(id)sender
{
    if([self.txtpwd.text isEqualToString:@""])
    {
        [Common showMsg:@"密码不能为空！" andCancel:YES andHost:self];
    }
    else if (![self.txtpwd.text isEqualToString:self.txtpwdagain.text])
    {
        [Common showMsg:@"两次输入的密码不一致" andCancel:YES andHost:self];
    }
    
    operation=[[ForgetPwdOperation alloc] initWithDelegate:self];
    
    NSString *url= [FxGlobal getServiceUrl:@"user" andFuncName:@"Forget"];
    
    NSString *md5Str= [NSString stringWithFormat: @"djID=%@&pwd=%@&key=tqa",self.djid,self.txtpwd.text];
    
    NSString *sign = [Common createMD5:md5Str];
    
    NSString *body=[NSString stringWithFormat:@"{\"djID\":\"%@\",\"pwd\":\"%@\",\"sign\":\"%@\",\"clicentid\":\"1\"}",self.djid,self.txtpwd.text,sign];
    
    NSDictionary *dictInfo = @{@"url":url,@"body":body};
    
    [operation setOpInfo:dictInfo];
    
    [operation post];
}




-(void) opSuccessForPost:(id)data
{
    NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
    NSDictionary *data1 = [dataStr objectFromJSONString];
    
    NSString *v=[data1 objectForKey:@"result"];
    
    if([v isEqualToString:@"1"])
    {
        dispatch_async(dispatch_get_main_queue(), ^{
            LoginAction *la=[[LoginAction alloc] init];
            [self.navigationController pushViewController:la animated:true];
        });
    }
    else
    {
        [Common showMsg:@"修改密码失败，请稍后再试！" andCancel:YES andHost:self];
    }
}

@end
